package com.example.classcommunity3.service;

import com.example.classcommunity3.dao.TeacherDao;
import com.example.classcommunity3.model.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherService {

    @Autowired
    TeacherDao teacherDao;

    public boolean signIn(Long account, String name){

        boolean b;

        try{
            Teacher insertTeacher = new Teacher();
            insertTeacher.settAccount(account);
            insertTeacher.settName(name);
            teacherDao.save(insertTeacher);
            b = true;
        }
        catch (Exception e){
            b = false;
        }
        return b;
    }

    public boolean changeInfo(Long account, String name){
        Teacher teacher = teacherDao.findByTAccount(account);

        if (teacher != null){
            try {
                teacher.settName(name);
                teacherDao.save(teacher);
                return true;
            }
            catch (Exception e){
                return false;
            }
        }
        return false;
    }

    public String getTName(Long account){
        Teacher teacher = teacherDao.findByTAccount(account);
        String name = teacher.gettName();

        return name;
    }
}
